//
//  ListTableViewCell.m
//  FNMenu
//
//  Created by 航汇聚科技 on 2018/9/6.
//  Copyright © 2018年 Yi Zhou. All rights reserved.
//

#import "ListTableViewCell.h"
#import "TagCollectionViewCell.h"

@implementation ListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (self.tags.count > 5) {
        return 5;
    }
    return self.tags.count;
}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    TagCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TagCollectionCell" forIndexPath:indexPath];
    cell.label.text = self.tags[indexPath.item];
    cell.layer.borderColor = [UIColor colorWithRed:252./255. green:150./255. blue:95./255. alpha:1].CGColor;
    cell.layer.borderWidth = 1.0;
    cell.layer.cornerRadius = 2;
    cell.layer.masksToBounds = YES;
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *text = self.tags[indexPath.item];
    CGFloat extraWidth = 10;
    UIFont *font = [UIFont fontWithName:@"AppleSDGothicNeo-Regular" size:13.0];
    CGSize size = CGSizeMake(MAXFLOAT, 30.0f);
    CGSize buttonSize = [text boundingRectWithSize:size
                                           options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                        attributes:@{NSFontAttributeName:font}
                                           context:nil].size;
    return CGSizeMake(buttonSize.width + extraWidth, buttonSize.height + 6);
}

@end

